<template>
    <view>
        <!-- pages/pay/index.wxml -->
        <view style="text-align: center; padding: 40px 0px; font-size: 30px">加入JFinal开发者计划</view>
        <view style="text-align: center; color: red; padding: 0px 0px 40px 0px; font-size: 30px">0.1元</view>
        <button type="primary" @tap="startPay">确认加入并支付</button>
    </view>
</template>

<script>
// pages/pay/index.js
//获取应用实例
const app = getApp();
const JBolt = app.globalData.getJBolt();
export default {
    data() {
        return {
            paying: false
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    methods: {
        startPay: function () {
            let paying = this.paying;

            if (paying) {
                return false;
            }

            this.setData({
                paying: true
            });
            var that = this;
            JBolt.apiGet({
                url: JBolt.API.test.unifiedorder
            }).then((res) => {
                let orderId = res.data.orderId;
                let payInfo = res.data.payInfo; // wx.hideLoading();

                uni.requestPayment({
                    timeStamp: payInfo.timeStamp,
                    nonceStr: payInfo.nonceStr,
                    package: payInfo.package,
                    signType: payInfo.signType,
                    paySign: payInfo.paySign,
                    success: function (res) {
                        that.setData({
                            paying: false
                        });
                        JBolt.MsgBox.info('支付成功', 500);
                    },
                    fail: function (res) {
                        JBolt.MsgBox.info('支付失败', 500, function () {
                            that.setData({
                                paying: false
                            });
                        });
                    }
                });
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
